--- /dev/null
+use crate::{Checksum, ObjectType};
+use glib::prelude::*;
+use glib::translate::*;
+use glib_sys::GFALSE;
+use std::error::Error;
+use std::ptr;
+
+pub fn checksum_file<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(
+ f: &P,
+ objtype: ObjectType,
+ cancellable: Option<&Q>,
+) -> Result<Checksum, Box<dyn Error>> {
+ unsafe {
+ let mut out_csum = ptr::null_mut();
+ let mut error = ptr::null_mut();
+ let ret = ostree_sys::ostree_checksum_file(
+ f.as_ref().to_glib_none().0,
+ objtype.to_glib(),
+ &mut out_csum,
+ cancellable.map(|p| p.as_ref()).to_glib_none().0,
+ &mut error,
+ );
+
+ if !error.is_null() {
+ Err(Box::<glib::Error>::new(from_glib_full(error)))
+ } else if ret == GFALSE {
+ Err(Box::new(glib_bool_error!(
+ "unknown error in ostree_checksum_file"
+ )))
+ } else {
+ Ok(Checksum::from_glib_full(out_csum))
+ }
+ }
+}
mod checksum;
#[cfg(any(feature = "v2018_6", feature = "dox"))]
mod collection_ref;
+mod functions;
#[cfg(any(feature = "v2019_3", feature = "dox"))]
mod kernel_args;
mod object_name;
pub use crate::checksum::*;
#[cfg(any(feature = "v2018_6", feature = "dox"))]
pub use crate::collection_ref::*;
+pub use crate::functions::*;
#[cfg(any(feature = "v2019_3", feature = "dox"))]
pub use crate::kernel_args::*;
pub use crate::object_name::*;
-use functions::{object_name_deserialize, object_name_serialize, object_to_string};
+use crate::{object_name_deserialize, object_name_serialize, object_to_string};
use glib;
use glib::translate::*;
use glib::GString;
use glib::IsA;
use glib_sys;
use ostree_sys;
+#[cfg(feature = "futures")]
use std::boxed::Box as Box_;
use std::collections::{HashMap, HashSet};
use std::path::Path;
--- /dev/null
+use gio::NONE_CANCELLABLE;
+use glib::Cast;
+use ostree::{checksum_file, ObjectType, RepoFile, RepoFileExt};
+use util::TestRepo;
+
+#[test]
+fn should_checksum_file() {
+ let repo = TestRepo::new();
+ repo.test_commit("test");
+
+ let file = repo
+ .repo
+ .read_commit("test", NONE_CANCELLABLE)
+ .expect("read commit")
+ .0
+ .downcast::<RepoFile>()
+ .expect("downcast");
+ let result = checksum_file(&file, ObjectType::File, NONE_CANCELLABLE).expect("checksum file");
+
+ assert_eq!(file.get_checksum().unwrap(), result.to_string());
+}
#[macro_use]
extern crate maplit;
+mod functions;
mod repo;
mod util;